#发送post请求，对网页的局部信息进行抓取，以百度翻译为例
import json

import requests
if __name__ =='__main__':
    post_url = 'https://fanyi.baidu.com/sug'
    word = input('enter a word:')
    data = {
        'kw':'word'
    }
    #UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.76'
    }
    response = requests.post(url=post_url,data=data,headers=headers)
    # 获取响应数据,使用json方法，返回obj，确认服务器响应数据是json，才可以使用json
    dic_obj = response.json()
    print(dic_obj)
    # 持久化存储
    fileName = word+'.json'
    fp = open(fileName,'w',encoding='utf-8')
    json.dump(dic_obj,fp=fp,ensure_ascii=False)
    print('over')